<template>
	<router-link :to="to" :activeClass="activeClass" @click.native="checkLink">
		<slot />
	</router-link>
</template>

<script>
	export default {
		name: 'ReLink',
		props: {
			to: {type: Object | String, default: '#'},
			activeClass: {type: String}
		},
		methods: {
			checkLink () {
				let pathname = window.location.pathname;
				let href = this.$el.getAttribute('href');
				if (href === undefined) {
					return;
				}
				let link = href;
				if (href.indexOf('#') !== -1) {
					link = href.substring(0, href.indexOf('#'));
				}
				if (link.indexOf('?') !== -1) {
					link = link.substring(0, link.indexOf('?'));
				}
				if (link === pathname) {
					this.$router.go(0);
				} else {
				}
			}
		}
	};
</script>
